package com.question.java.time.exec08;

import java.time.Duration;
import java.time.Instant;
import java.util.concurrent.TimeUnit;

/**
 * @Description: 对某个方法进行倒计时
 * @Author: Jun Yang
 */
public class DateTimeExample42 {

    public static double getTiming(Instant start, Instant end) {
        return Duration.between(start, end).toMillis() / 1000;
    }

    public static void main(String[] args) throws InterruptedException {
        Instant start = Instant.now();
        // 调用需要计时的方法
        TimeUnit.SECONDS.sleep(2); //模拟调用方法耗时
        Instant end = Instant.now();
        System.out.println(getTiming(start, end) + " second.");
    }

}
